#ifndef _LRUCACHE_H_
#define _LRUCACHE_H_
#include "Common.h"


class CacheItem;
class Item;

class LRUCache
{
public:
    LRUCache();
    ~LRUCache();
    int Init(u64 max_mem_size);
    void Destroy();

    int GetItem(Item *item, char *buf);
    int UpdateItem(Item* item_new, Item* item_old, const char *buf);
    int DeleteItem(Item* item);
    int SetItem(Item *item, const char *buf);
    void Resize(u64 new_size);

    u64 GetMemSize();
    u32 GetItemCount();


private:
    void release_space(u64 size);

    CacheItem *head;
    CacheItem *tail;

    u32 item_count;
    u64 mem_limit;
    u64 mem_used;

    RWLock lock;
};


#endif

